<!doctype html>
<html lang="en">
    <head>
		<meta charset="utf-8">
        <meta name="description" content="LegoCMS">
        <#include "../include_page/link.html"/>
        <script type="text/javascript">
        	var jq = $(function() {
        		var url = ctx + "/admin/directive/cmsFileList";
        		initMyPagination("MyPagination-file-list", "Template-file-list", url, function(data) {
            		$('#path').html(data.page.param.path);
        		});
        	});
			function query(code) {
        		$('.queryForm').find("input[name='parentCode']").val(code);
    			$('.query').click();
			}
			function createFile() {
				var parentCode = $('.queryForm').find("input[name='parentCode']").val();
				window.parent.showFormDialog("<@t.message 'title.file-add'/>", $('#add-file-modal'), function(form) {
					form.setForm({parentCode : parentCode});
				}, function() {
	    			$('.query').click();
				});
			}
			function createDir() {
				var parentCode = $('.queryForm').find("input[name='parentCode']").val();
				window.parent.showFormDialog("<@t.message 'title.dir-add'/>", $('#add-dir-modal'), function(form) {
					form.setForm({parentCode : parentCode});
				}, function() {
	    			$('.query').click();
				});
			}
			function uploadFile() {
				var parentCode = $('.queryForm').find("input[name='parentCode']").val();
				window.parent.showFormDialog("<@t.message 'title.file-upload'/>", $('#upload-modal'), function(form) {
					form.setForm({parentCode : parentCode});
				}, function() {
	    			$('.query').click();
				});
			}
			function del(code) {
				window.parent.showConfirm("<@t.message 'file.delete'/>", "<@t.message 'title.file-delete'/>", function() {
					var url = ctx + "/admin/file/delete";
					window.parent.ajaxSubmit(url, {code: code}, function() {
		    			$('.query').click();
					});
				})
			}
			function refresh() {
				var parentCode = $(".queryForm").find("input[name='parentCode']").val();
				var url = ctx + "/admin/file/synchronize";
				window.parent.ajaxSubmit(url, {parentCode : parentCode}, function() {
					window.parent.showMsg("<@t.message 'success'/>", 1, function() {
		    			$('.query').click();
					});
				});
			}
        </script>
    </head>
    <body>
        <div class="app-main__inner" id="MyPagination-file-list">
           	<form class="queryForm app-page-title">
           		<input type="hidden" name="parentCode"/>
	           	<div class="page-title-wrapper">
					<div class="form-inline">
						<div class="mb-2 mr-sm-2 mb-sm-0 position-relative form-group">
							<span class="btn btn-info" onclick="createFile()" ><@t.page 'btn.add-file'/></span>
						</div>
						<div class="mb-2 mr-sm-2 mb-sm-0 position-relative form-group">
							<span class="btn btn-info" onclick="createDir()" ><@t.page 'btn.add-dir'/></span>
						</div>
						<div class="mb-2 mr-sm-2 mb-sm-0 position-relative form-group">
							<span class="btn btn-info" onclick="uploadFile()" ><@t.page 'btn.upload'/></span>
						</div>
						<div class="mb-2 mr-sm-2 mb-sm-0 position-relative form-group">
							<span class="btn btn-info" onclick='refresh()'><@t.page 'btn.refresh'/></span>
						</div>
						<span class="query"></span>
					</div>
	            </div>
	        </form>
	        <div class="row row-fluid">
	            <div class="col-md-12">
	        	<span class="breadcrumb" id="path"></span>
	                <div class="main-card mb-3 card">
	                    <div class="card-header"><@t.page 'file.list'/></div>
	                    <div class="table-responsive">
	                        <table role="grid" class="align-middle mb-0 table table-borderless table-striped table-hover mytab">
	                            <thead>
	                                <tr role="row">
	                                    <th class="text-center"><@t.page 'list.type'/></th>
	                                    <th class="text-left"><@t.page 'list.name'/></th>
	                                    <th class="text-center"><@t.page 'list.update-time'/></th>
	                                    <th class="text-center"><@t.page 'list.create-time'/></th>
	                                    <th class="text-center"><@t.page 'list.size'/>(B)</th>
	                                    <th class="text-center"><@t.page 'list.operation'/></th>
	                                </tr>
	                            </thead>
                        		<tbody></tbody>
	                        </table>
	                    </div>
	                    <div class="d-block text-center card-footer widget-content-rigth">
	                    	<nav class="" aria-label="Page navigation example">
	                    	<div class="tempContentDiv"></div>
				   			<p style="display: none">
					            <textarea id="Template-file-list" rows="0" cols="0">
					                <!--
					                    {#template MAIN}
					                        {#if $T.page.param.parentCode != '-'}
					                            <tr role="row" >
					                                <td class="text-center" style="font-size: 1.5rem;"><i id="icon-view" class="pe-7s-back"></i></td>
					                                <td class="text-left"><a href="#" onclick="query({$T.page.param.parentCode})"><@t.page 'btn.back'/></a></td>
					                                <td class="text-center"></td>
					                                <td class="text-center"></td>
					                                <td class="text-center"></td>
					                                <td class="text-center"></td>
					                            </tr>
					                        {#/if}
					                        {#foreach $T.page.result as Result}
					                            <tr role="row" >
					                                <td class="text-center" style="font-size: 1.5rem;">
					                                	{#if $T.Result.type.code == 'dir'}
					                                		<i id="icon-view" class="pe-7s-wallet"></i>
					                                	{#else}
					                                		<i id="icon-view" class="pe-7s-copy-file"></i>
					                                	{#/if}
					                                </td>
					                                <td class="text-left">
					                                	{#if $T.Result.type.code == 'dir'}
					                                		<a href="#" onclick="query({$T.Result.code})">{$T.Result.name}</a>
					                                	{#else}
					                                		{$T.Result.name}
					                                	{#/if}
					                                </td>
					                                <td class="text-center">{$T.Result.updateTime}</td>
					                                <td class="text-center">{$T.Result.createTime}</td>
					                                <td class="text-center">{$T.Result.size}</td>
					                                <td class="text-center">
					                                	{#if $T.Result.type.code == 'file'}
					                                		{#if $T.Result.editable}
					                                			<button class="btn btn-primary btn-sm" onclick="window.parent.addTab('file-add', '<@t.message 'title.file-modify'/>', '/admin/file/edit/{$T.Result.code}')"><@t.page 'btn.edit'/></button>
					                                		{#else}
					                                			<a class="btn btn-primary btn-sm" href="${site.path}{$T.Result.path}" target="_blank"><@t.page 'btn.view'/></a>
					                                		{#/if}
					                                	{#/if}
					                                	<button class="btn btn-danger btn-sm" onclick="del({$T.Result.code})"><@t.page 'btn.delete'/></button>
					                                </td>
					                            </tr>
					                        {#/for}
					                    {#/template MAIN}
					                -->
					            </textarea>
				        	</p>
	                    	</nav>
	                   	</div>
	                </div>
	            </div>
	        </div>
	    </div>
		<#include "add-file-modal.html"/>
		<#include "add-dir-modal.html"/>
		<#include "upload-modal.html"/>
    </body>
</html>
